package com.ler.yrmall.product.controller;

import com.ler.yrmall.basic.Form;
import com.ler.yrmall.basic.Result;
import com.ler.yrmall.product.entity.SkuEntity;
import com.ler.yrmall.product.form.SkuForm;
import com.ler.yrmall.product.service.SkuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * sku
 * @author Leron
 */
@RestController
@RequestMapping("/sku")
public class SkuController {

    @Resource
    private SkuService skuService;

    @RequestMapping("/listBySpuId/{spuId}")
    public Result<?> listBySpuId(@PathVariable("spuId") Long spuId) {
        return Result.ok(skuService.listSkuBySpuId(spuId));
    }

    @RequestMapping("/list")
    public Result<?> list(Form request) {
        return Result.ok(skuService.list(request));
    }


    /**
     * 信息
     */
    @RequestMapping("/getById/{skuId}")
    public Result<?> getById(@PathVariable("skuId") Long skuId) {
        return Result.ok(skuService.getById(skuId));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody SkuEntity skuInfo) {
        skuService.save(skuInfo);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody SkuEntity skuInfo) {
        skuService.updateById(skuInfo);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        skuService.deleteSku(id);
        return Result.ok();
    }


    // 移动端

    @GetMapping("/getById/{skuId}")
    public Result<?> getSkuById(@PathVariable Long skuId) {
        return Result.ok(skuService.getSkuById(skuId));
    }

    @GetMapping("/find")
    public Result<?> find(SkuForm request) {
        return Result.ok(skuService.pageGroupBySpuId(request));
    }
}
